<template>
  <div v-show="isActive" class="tab-panel">
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: 'Tab',
  props: {
    title: {
      type: String,
      required: true,
    },
    index: {
      type: Number,
      required: true,
    },
  },
  data() {
    return {};
  },
  computed: {
    isActive() {
      return this.tabs.activeTab() === this.index;
    },
  },
  inject: ['tabs'],
  created() {
    this.tabs.register(this);
  },
  beforeDestroy() {
    this.tabs.unregister(this);
  },
};
</script>

<style scoped>
.tab-panel {
  position: relative;
  height: 100%;
  animation: fadeIn 0.3s ease;
  color: #fff;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}
</style>
